package com.dianping.cat.alarm.policy.transform;

import com.dianping.cat.alarm.policy.entity.AlertPolicy;
import com.dianping.cat.alarm.policy.entity.Group;
import com.dianping.cat.alarm.policy.entity.Level;
import com.dianping.cat.alarm.policy.entity.Type;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;







public class DefaultDomMaker
  extends Object
  implements IMaker<Node>
{
  public AlertPolicy buildAlertPolicy(Node node) { return new AlertPolicy(); }





  public Group buildGroup(Node node) {
/*  27 */     String id = getAttribute(node, "id");

    return new Group(id);
  }




  public Level buildLevel(Node node) {
    String id = getAttribute(node, "id");
/*  37 */     String send = getAttribute(node, "send");
/*  38 */     String suspendMinute = getAttribute(node, "suspendMinute");
/*  39 */     String recoverMinute = getAttribute(node, "recoverMinute");

/*  41 */     Level level = new Level(id);

/*  43 */     if (send != null) {
/*  44 */       level.setSend(send);
    }

/*  47 */     if (suspendMinute != null) {
/*  48 */       level.setSuspendMinute((Integer)convert(Integer.class, suspendMinute, null));
    }

/*  51 */     if (recoverMinute != null) {
/*  52 */       level.setRecoverMinute((Integer)convert(Integer.class, recoverMinute, null));
    }

/*  55 */     return level;
  }


  public Type buildType(Node node) {
/*  60 */     String id = getAttribute(node, "id");

/*  62 */     return new Type(id);
  }




  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/*  69 */     if (value == null || value.length() == 0) {
/*  70 */       return defaultValue;
    }

/*  73 */     if (type == Boolean.class || type == boolean.class)
/*  74 */       return (T)Boolean.valueOf(value); 
/*  75 */     if (type == Integer.class || type == int.class)
/*  76 */       return (T)Integer.valueOf(value); 
/*  77 */     if (type == Long.class || type == long.class)
      return (T)Long.valueOf(value);
/*  79 */     if (type == Short.class || type == short.class)
/*  80 */       return (T)Short.valueOf(value); 
/*  81 */     if (type == Float.class || type == float.class)
/*  82 */       return (T)Float.valueOf(value); 
/*  83 */     if (type == Double.class || type == double.class)
/*  84 */       return (T)Double.valueOf(value); 
/*  85 */     if (type == Byte.class || type == byte.class)
/*  86 */       return (T)Byte.valueOf(value); 
/*  87 */     if (type == Character.class || type == char.class) {
/*  88 */       return (T)Character.valueOf(value.charAt(0));
    }
/*  90 */     return (T)value;
  }


  protected String getAttribute(Node node, String name) {
/*  95 */     Node attribute = node.getAttributes().getNamedItem(name);

/*  97 */     return (attribute == null) ? null : attribute.getNodeValue();
  }

  protected Node getChildTagNode(Node parent, String name) {
/* 101 */     NodeList children = parent.getChildNodes();
/* 102 */     int len = children.getLength();

/* 104 */     for (int i = 0; i < len; i++) {
/* 105 */       Node child = children.item(i);

/* 107 */       if (child.getNodeType() == 1 && 
/* 108 */         child.getNodeName().equals(name)) {
/* 109 */         return child;
      }
    }


/* 114 */     return null;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-alarm-3.0.0.jar!/com/dianping/cat/alarm/policy/transform/DefaultDomMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */